package gateway

import (
	"cowb/rpcpool"
)

type Gateway struct{}

func (this *Gateway) Regist(msg *RegistMsg, reply *[]byte) (err error) {
	for i := 0; i < len(msg.Cmds); i++ {
		rpcpool.Bind(msg.Cmds[i], msg.Host, msg.ServiceName)
	}
	*reply = []byte("ok")
	return
}

func (this *Gateway) TransRPC(msg *TransMsg, reply *[]byte) (err error) {
	*reply, err = rpcpool.Call(msg.Cmd, msg.Body)
	return
}

func Run(gwHost string, rpcHost string) {
	go rpcpool.Listen(rpcHost, new(Gateway))
	new(gwhttp).Run(gwHost)
}
